//
//  RegularExpressionsUtils.swift
//  AnJiBei
//
//  Created by 赵鑫 on 15/10/31.
//  Copyright © 2015年 赵鑫. All rights reserved.
//

import Foundation


class RegularExpressionsUtils {
    
    
    private static func myCheckRegex(pattern: String, str: String) -> Bool {
    
        do {
        
            let regex = try NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.CaseInsensitive)
            
            let res = regex.matchesInString(str, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, str.characters.count))

            PrintUntils.printLog("res", message: res)
            
            
            for checkingRes in res {
                debugPrint("***********************************\n")
                print((str as NSString).substringWithRange(checkingRes.range))
                debugPrint("\n***********************************\n")
                
            }
            
            if res.count > 0 {
            
                return true
            }
            
            else {
            
                return false
                
            }

            

        }
        catch {
        
            debugPrint("***********************************\n")
            debugPrint(error)
            debugPrint("\n***********************************\n")
            return false

        }
        
    }
    
    /**
     手机号验证
     
     :param: PhoneNumber
     
     :returns:
     */
    static func regularExpressionPhone (PhoneNumber:String) -> Bool {
        
        let phonePattern = "^1[0-9]{10}$"
        
        return myCheckRegex(phonePattern, str: PhoneNumber)
        
    }
    
//    /**
//     
//     总验证 ，私有
//     :param: regularPattern
//     :param: regularInput
//     
//     :returns:
//     */
//    private static func regularExpression(regularPattern: String, regularInput: String )->Bool {
//        
//        
//        let matcher = MyRegex(regularPattern)
//        
//        return matcher.match(regularInput)
//        
//    }
//    
//    /**
//     网址匹配正则表达式
//     
//     :param: HttpURL 网址
//     
//     :returns: 为网址则为真，非为假
//     */
////    static func regularExpressionURL (HttpURL:String)->Bool {
////        let urlPattern = "^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$"
////        
////        return regularExpression(urlPattern, regularInput: HttpURL)
////        return true
////    }
//    
//    /**
//     邮箱验证
//     
//     :param: MailAddress <#MailAddress description#>
//     
//     :returns: <#return value description#>
//     */
//    
//    static func regularExpressionMail (MailAddress:String) -> Bool {
//        
//        let mailPattern = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
//        
//        return regularExpression(mailPattern, regularInput:MailAddress)
//        
//    }
//    

}
